/*获取十六进制随机颜色*/
function getRandomColor () {
    return '#' + (function(h) {
        return new Array(7 - h.length).join("0") + h;
    })((Math.random() * 0x1000000 << 0).toString(16));
}

/*动态加载js css*/
function jsorcss(type, url) {
    try {
        var s = "";
        var date = new Date();
        date = date.getMilliseconds();
        date = date.toString();
        if(type == 'css') {
            s = "<link rel='stylesheet' href=" + url + ".css?v=" + date + " media='all'/>"
            $(s).appendTo('head');
        } else if(type == 'js') {
            s = "<script type='text/javascript' src=" + url + ".js?v=" + date + "></script>";
            $(s).appendTo('body');
        }
    } catch(e) {
        console.log(e)
    }
}

 /**
   * JS颜色十六进制转换为rgb或rgba,返回的格式为 rgba（255，255，255，0.5）字符串
   * sHex为传入的十六进制的色值
   * alpha为rgba的透明度
   */
function colorRgba: (sHex, alpha = 1) => {
    // 十六进制颜色值的正则表达式
    var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
    /* 16进制颜色转为RGB格式 */
    let sColor = sHex.toLowerCase()
    if (sColor && reg.test(sColor)) {
      if (sColor.length === 4) {
        var sColorNew = '#'
        for (let i = 1; i < 4; i += 1) {
          sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1))
        }
        sColor = sColorNew
      }
      //  处理六位的颜色值
      var sColorChange = []
      for (let i = 1; i < 7; i += 2) {
        sColorChange.push(parseInt('0x' + sColor.slice(i, i + 2)))
      }
      // return sColorChange.join(',')
      // 或
      return 'rgba(' + sColorChange.join(',') + ',' + alpha + ')'
    } else {
      return sColor
    }
}